﻿using System;
using RegexpMatching.Matchers;

namespace RegexpMatching
{
  class Program
  {
    static void Main(string[] args)
    {
      WriteWelcome();
      Run();
      WriteExit();
    }

    #region "Buisness Logic"
    private static void Run()
    {
      bool exitCondition;
      do
      {
        WritePrompt();
        string input = Console.ReadLine();
        exitCondition = CheckIfExitCondition(input);
        if (!exitCondition)
        {
          bool isPhone = PhoneMatcher.IsMatch(input);
          bool isIndex = IndexMatcher.IsMatch(input);
          bool isEMail = EMailMatcher.IsMatch(input);

          WriteResult(isEMail, isIndex, isPhone);
        }
      } while (!exitCondition);
    }
    private static bool CheckIfExitCondition(string input)
    {
      return input == null || input.Trim() == string.Empty;
    }
    #endregion "Buisness Logic"

    #region "Printing"
    private static void WriteResult(bool isEMail, bool isIndex, bool isPhone)
    {
      if (isPhone && isIndex)
      {
        Console.WriteLine(Messages.AnswerIndexAndPhone);
      }
      else if (isPhone)
      {
        Console.WriteLine(Messages.AnswerPhone);
      }
      else if (isIndex)
      {
        Console.WriteLine(Messages.AnswerIndex);
      }
      if (isEMail)
      {
        Console.WriteLine(Messages.AnswerEmail);
      }

      if (!(isPhone || isEMail || isIndex))
      {
        Console.WriteLine(Messages.AnswerNotMatches);
      }
    }

    private static void WriteExit()
    {
      Console.WriteLine(Messages.ExitMessage);
    }

    private static void WriteWelcome()
    {
      Console.WriteLine(Messages.WelcomeMessage);
      Console.WriteLine(Messages.ExitDescriptionMessage);
    }

    private static void WritePrompt()
    {
      Console.WriteLine();
      Console.WriteLine(Messages.Prompt);
    }
    #endregion "Printing"
  }
}
